package test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import dbBean.DBConnManager;

public class Jiaoshi {
	
	private static DBConnManager dbConnManager = new DBConnManager();
	
	public static boolean jianchaMima(String s) throws SQLException {
		boolean result = false;
		
		Connection conn = dbConnManager.getConnection("mysql");
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT mima FROM xtxxb");
		if (rs.next()) {
			String xtmm = rs.getString("mima");	// 系统管理员密码
			if (s.equals(xtmm)) {
				result = true;
			}
		}
		stmt.close();
		dbConnManager.releaseConnection("mysql", conn);
		
		return result;
	}
	
	public static String getZhucema() throws SQLException {
		String zcm = null;
		Connection conn = dbConnManager.getConnection("mysql");
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT zcm FROM xtxxb");
		if (rs.next()) {
			zcm = rs.getString("zcm");	// 注册码
		}
		stmt.close();
		dbConnManager.releaseConnection("mysql", conn);
		return zcm;
	}
	
	public static boolean updateZhucema(String zcm) {
		boolean success = false;
		
		Connection conn = dbConnManager.getConnection("mysql");
		try {
			Statement stmt = conn.createStatement();
			stmt.executeUpdate("update xtxxb set zcm=" + "'" + zcm + "'");
			stmt.close();
			
			success = true;
		} catch (SQLException e) {
			e.printStackTrace();
			success = false;
		}
		
		dbConnManager.releaseConnection("mysql", conn);
		
		return success;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
